package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal")
public class SetmealController {

    @Reference
    SetmealService service;

    @RequestMapping("/getSetmeal")
    public Result getSetmeal (){
        try {
            List<Setmeal> setmealList = service.findAll();
            return new Result(true, MessageConst.QUERY_SETMEALLIST_SUCCESS,setmealList);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConst.QUERY_SETMEALLIST_FAIL);
        }

    }

    @RequestMapping("/findById")
    public Result findById (Integer id){

        try {
            Setmeal setmeal =  service.findById(id);
            return  new Result(true,MessageConst.GET_SETMEAL_LIST_SUCCESS,setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return  new Result(false,MessageConst.GET_SETMEAL_LIST_FAIL);
        }

    }

}
